<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<!DOCTYPE>
<html>
<head content="-注册">
    <%@ include file="/resources/modular/head/outside-head.jsp" %>
</head>
<body>
<div class="loading"></div>
<header class="header">新用户注册</header>
<div class="page">
    <div class="registerpage">
        <p class="registerpage_title">
            <em>账户设置</em>
            <span id="regster_point">请设置你的工厂码，手机号、用户名和密码用于登录</span></p>

        <form class="register_form">
            <p>
                <span><i>*</i>工厂码</span>
                <input class="register_factoryCode" type="text" placeholder="请输入工厂码" required name="factoryCode">
                <i class="point">请输入5-8位数字</i></p>
            <p>
                <span><i>*</i>手机号</span>
                <input class="register_tel" type="tel" placeholder="请输入手机号" required name="mobile">
                <i class="point">请正确输入手机号码</i></p>
            <p>
                <span><i>*</i>用户名</span>
                <input class="register_username" type="text" placeholder="请设置用户名" required name="username">
                <i class="point">请输入5-20位数字、字母或下划线</i></p>
            <p>
                <span><i>*</i>登录密码</span>
                <input class="register_setpassword" type="password" placeholder="请设置登录密码" required name="">
                <i class="point">请输入6-18位数字、字母或下划线</i></p>
            <p>
                <span><i>*</i>确认密码</span>
                <input class="register_password" type="password" placeholder="请再次输入登录密码" required name="">
                <i class="point">您两次输入的密码不一致</i></p>
            <p>
                <span><i>*</i>验证码</span>
                <input class="register_imagecode" type="text" placeholder="请输入验证码" required name="imgcode">
                <a class="register_imagecodeurl" href="javascript:;">
                    <img onclick="chageCode()" id="captchaImage" src="${basePath}v2/authCode">
                    <span onclick="chageCode()">&nbsp;换一张</span>
                </a>
                <i class="point">请正确输入验证码</i></p>
            <div class="register_hr"></div>
            <p>
                <span><i>*</i>验证码</span>
                <input class="register_telcode" type="text" placeholder="请输入短信验证码" required name="smscode">

                <input type="hidden" name="password">

                <a class="register_telcodeurl" href="javascript:;">获取短信验证码</a>
                <i class="point">请正确输入短信验证码</i></p>
            <div class="register_terms">
                <span class="register_sp1 cur"></span>
                <span class="register_sp2">已阅读并接受游艺云<a href="javascript:;">《版权声明》</a>和<a href="javascript:;">《隐私保护》</a></span>
                <i class="point">请接受《版权声明》和《隐私保护》</i></div>
            <input class="register_btn" type="button" value="确 认">
        </form>
    </div>
</div>

<div id="GC_childinfo_remove" class="login_common_pointpage_dv" style="display:none;">
    <div class="login_common_pointpage">
        <p class="cur">恭喜,您的账户注册成功.</p>
        <div><a class="login_common_pointpagebtn" href="javascript:;"
                onclick="javascript:window.location = '${basePath}v2/account/todayView'">确认</a></div>
    </div>
</div>

</body>
</html>
<%@ include file="/resources/modular/foot/outside_footer.jsp" %>
<script type="text/javascript" src="${basePath}resources/js/v2/youyicloud-md5.js"></script>
<script type="text/javascript">

    var regusername = /^\w{5,20}$/;
    var reguserpassword = /^[\w`~!@#\$%\^&\*\(\)_\+-=\[\]\\\{\}\|;':",\.\/<>\?]{6,18}$/;
    var regusertel = /^1[34578]\d{9}$/;
    var reguserFactoryCode=/^\d{5,8}$/;

    <%--更新图片验证码--%>
    function chageCode() {
        $('#captchaImage').attr('src', '${basePath}v2/authCode?abc=' + Math.random());//链接后添加Math.random，确保每次产生新的验证码，避免缓存问题。
    }

    <%--获取短信验证码--%>
    function getsmscode() {
        $.ajax({
            url: '${basePath}v2/sms/sendcodebymoblie',
            type: 'POST',
            data: {
                "mobile": $(".register_tel").val(),
                "imgcode": $(".register_imagecode").val()
            },
            error: function (response) {
                $errorMsg(response);
            },
            success: function (ret) {
                if (ret.result) {
                    alert("验证码已发送至"+ret.info+",请注意查收", "cur");
                } else {
                    if (ret.ERROR == "smscode") {
                        $(".register_telcode~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "imgcode") {

                        clearInterval(timer);
                        s = 0;
                        $(".register_telcodeurl").text("获取短信验证码").removeClass("cur");
                        getCaptcha();

                        $(".register_imagecode~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "mobile") {
                        $(".register_tel~.point").text(ret.info).addClass("cur");
                    } else {
                        $("#regster_point").text(ret.info).addClass("cur");
                    }
                }
            }
        });
    }

    <%--注册用户信息--%>
    function submitUserinfo() {
        var password = $(".register_password").val();
        $("input[name='password']").val(createPassword(password, password));
        $.ajax({
            url: '${basePath}v2/register/submitUserInfo',
            type: 'POST',
            data: $(".register_form").serialize(),
            error: function (response) {
                $errorMsg(response);
            },
            success: function (ret) {
                if (ret.result) {
                    $("#GC_childinfo_remove").show();
                } else {
                    if (ret.ERROR == "smscode") {
                        $(".register_telcode~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "imgcode") {
                        $(".register_imagecode~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "username") {
                        $(".register_username~.point").text(ret.info).addClass("cur");
                    } else if (ret.ERROR == "factorycode") {
                        $(".register_factoryCode~.point").text(ret.info).addClass("cur");
                    }else {
                        $("#regster_point").text(ret.info).addClass("cur");
                    }
                }
            }
        });
    }

    //点击获取短信验证码
    var timer;
    var getCaptcha = function () {
        $(".register_telcodeurl").on("click", function () {
            var register_factory=$(".register_factoryCode").val();
            var register_tel = $(".register_tel").val();
            var register_username = $(".register_username").val();
            var register_setpassword = $(".register_setpassword").val();
            var register_password = $(".register_password").val();
            var register_imagecode = $(".register_imagecode").val();
            if(register_factory==""){
                $(".register_factoryCode~.point").text("工厂码不能为空").addClass("cur");

            }else if(!(reguserFactoryCode.test(register_factory))){
                $(".register_factoryCode~.point").text("请正确输入5-8位数字工厂码").addClass("cur");

            }else if (register_tel == "") {
                $(".register_tel~.point").text("请输入手机号码").addClass("cur");

            } else if (!(regusertel.test(register_tel))) {
                $(".register_tel~.point").text("请正确输入11位手机号码").addClass("cur");

            } else if (register_username == "") {
                $(".register_username~.point").text("请输入用户名").addClass("cur");

            } else if (!(regusername.test(register_username))) {
                $(".register_username~.point").text("请输入5-20位数字、字母或下划线").addClass("cur");

            } else if (register_setpassword == "") {
                $(".register_setpassword~.point").text("请输入登录密码").addClass("cur");

            } else if (!(reguserpassword.test(register_setpassword))) {
                $(".register_setpassword~.point").text("请输入6-18位数字、字母或英文符号").addClass("cur");

            } else if (register_password == "") {
                $(".register_password~.point").text("请输入确认密码").addClass("cur");

            } else if (register_password != register_setpassword) {
                $(".register_password~.point").text("您二次输入的密码不一致").addClass("cur");

            } else if (register_imagecode == "") {
                $(".register_imagecode~.point").text("验证码不能为空").addClass("cur");

            } else if (regusertel.test(register_tel) && regusername.test(register_username) && reguserpassword.test(register_setpassword) && register_setpassword == register_password && register_imagecode != "") {
                if (!$(".register_telcodeurl").hasClass("cur")) {
                    $(".register_telcodeurl").text("重新发送（60s）").addClass("cur");
                    $(".register_telcodeurl").unbind("click");
                    var s = 0;
                    timer = setInterval(function () {
                        if (s < 60) {
                            $(".register_telcodeurl").text("重新发送（" + (60 - s) + "s）");
                            s++;
                        } else if (s >= 60) {
                            clearInterval(timer);
                            s = 0;
                            $(".register_telcodeurl").text("获取短信验证码").removeClass("cur");
                            getCaptcha();
                        }
                    }, 1000);

                    /*获取短信验证码*/
                    getsmscode();
                }
            }
        });
    };
    getCaptcha();

</script>